package cn.com.headfree.xxk.dao.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Repository;

import com.gta.edu.sdk.base.dao.impl.BaseDaoImpl;
import com.gta.edu.sdk.util.StringUtil;

import cn.com.headfree.entity.TContiStudyInfo;
import cn.com.headfree.entity.TEducateInfo;
import cn.com.headfree.entity.TProTecInfo;
import cn.com.headfree.entity.TSkillLevelInfo;
import cn.com.headfree.xxk.dao.IMessageCardDao;
import cn.com.headfree.xxk.vo.UserVo;

@Repository("messageCardDao")
public class MessageCardDaoImpl extends BaseDaoImpl<TContiStudyInfo> implements IMessageCardDao {

	@Override
	public List<TContiStudyInfo> findContiStudyInfoByCondisByErpNo(String erpNo, String type) {
		String sql = "   select t.* " +
				" from t_conti_study_info t where t.is_valid='0'  and t.del_sign = '0' " ;
		StringBuilder sqlBuilder = new StringBuilder(sql);

		ArrayList<Object> arrayList = new ArrayList<Object>();
		if (!StringUtil.isNullOrEmpty(erpNo)) {
			sqlBuilder.append(" AND erp_no= ? ");
			arrayList.add(erpNo);
		}
		if (!StringUtil.isNullOrEmpty(type)) {
			sqlBuilder.append(" AND type= ? ");
			arrayList.add(type);
		}

		sqlBuilder.append(" order by start_time desc  ");
		return this.findAllBySQL(TContiStudyInfo.class, sqlBuilder.toString(), null, false, arrayList.toArray());
	}

	@Override
	public TEducateInfo getEduceteInfoByJyxl(String erpNo) {
		 String sql = "  select t.* " +
	                " from t_educate_info t " +
	                " where  t.is_valid='0' and t.del_sign = '0' AND is_employ_educ = '0' " ;
	        StringBuilder sqlBuilder = new StringBuilder(sql);

	        ArrayList<Object> arrayList = new ArrayList<Object>();
	        if (!StringUtil.isNullOrEmpty(erpNo)) {
	            sqlBuilder.append(" AND erp_no= ? ");
	            arrayList.add(erpNo);
	        }

	        sqlBuilder.append(" order by acqu_time desc limit 0,1 ");
	        return this.findUnique(TEducateInfo.class, sqlBuilder.toString(), arrayList.toArray());
	}

	@Override
	public TEducateInfo getEduceteInfoByZgxl(String erpNo) {
		 String sql = "  select t.* " +
	                " from t_educate_info t " +
	                " where  t.is_valid='0' and t.del_sign = '0' AND is_highest_educ = '0' " ;
	        StringBuilder sqlBuilder = new StringBuilder(sql);

	        ArrayList<Object> arrayList = new ArrayList<Object>();
	        if (!StringUtil.isNullOrEmpty(erpNo)) {
	            sqlBuilder.append(" AND erp_no= ? ");
	            arrayList.add(erpNo);
	        }

	        sqlBuilder.append(" order by acqu_time desc limit 0,1 ");
	        return this.findUnique(TEducateInfo.class, sqlBuilder.toString(), arrayList.toArray());
	}

	@Override
	public TSkillLevelInfo getTSkillLevelInfoByErpNo(String erpNo) {
		 String sql = "  select t.* " +
	                " from t_skill_level_info t where t.is_valid='0' and t.del_sign = '0' " ;
	        StringBuilder sqlBuilder = new StringBuilder(sql);

	        ArrayList<Object> arrayList = new ArrayList<Object>();
	        if (!StringUtil.isNullOrEmpty(erpNo)) {
	            sqlBuilder.append(" AND erp_no= ? ");
	            arrayList.add(erpNo);
	        }

	        sqlBuilder.append(" order by qualifi_level,acqu_time desc limit 0,1 ");
	        return this.findUnique(TSkillLevelInfo.class, sqlBuilder.toString(), arrayList.toArray());
	}

	@Override
	public TProTecInfo getTProTecInfoByErpNo(String erpNo) {
		String sql = "  select t.* " +
                " from t_pro_tec_info t where t.is_valid='0' and t.del_sign = '0' " ;
        StringBuilder sqlBuilder = new StringBuilder(sql);

        ArrayList<Object> arrayList = new ArrayList<Object>();
        if (!StringUtil.isNullOrEmpty(erpNo)) {
            sqlBuilder.append(" AND erp_no= ? ");
            arrayList.add(erpNo);
        }

        sqlBuilder.append(" order by subj_level,acqu_time desc limit 0,1");
        return this.findUnique(TProTecInfo.class, sqlBuilder.toString(), arrayList.toArray());
	}

	@Override
	public List<UserVo> getUsersByDeptId(String deptId) {
		String sql = "   select t.erp_no " +
				" from t_dept_emp_rela t where 1=1 " ;
		StringBuilder sqlBuilder = new StringBuilder(sql);

		ArrayList<Object> arrayList = new ArrayList<Object>();
		if (!StringUtil.isNullOrEmpty(deptId)) {
			sqlBuilder.append(" AND dept_id= ? ");
			arrayList.add(deptId);
		}
		return this.findAllBySQL(UserVo.class, sqlBuilder.toString(), null, false, arrayList.toArray());
	}

}
